﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using System.IO;

namespace Skyhook.Core.Graphics
{
    public static class GraphicsFactory
    {
        static GraphicsDevice GraphicsDevice = null;
        static ContentManager ContentManager = null;

        public static void Initialize(GraphicsDevice graphicsdevice, ContentManager contentmanager)
        {
            GraphicsDevice = graphicsdevice;
            ContentManager = contentmanager;
        }

        public static Texture2D CreateTexture2D(int width, int height, bool mipmap = false, SurfaceFormat format = SurfaceFormat.Color)
        {
            return new Texture2D(GraphicsDevice, width, height, mipmap, format);
        }

        public static Texture2D CreateTexture2DFromStream(Stream stream)
        {
            return Texture2D.FromStream(GraphicsDevice, stream);
        }

        public static Texture2D CreateTexture2DFromFile(string filename)
        {
            return ContentManager.Load<Texture2D>(filename);
        }

        public static SpriteFont CreateSpriteFontFromFile(string filename)
        {
            string fullname = StreamFactory.GetFullFileName(filename + ".xnb");
            return ContentManager.Load<SpriteFont>(fullname.Remove(fullname.Length - 4));
        }

        public static Effect CreateEffectFromFile(string filename)
        {
            string fullname = StreamFactory.GetFullFileName(filename + ".xnb");
            return ContentManager.Load<Effect>(fullname.Remove(fullname.Length - 4));
        }

        public static SpriteBatch CreateSpriteBatch()
        {
            return new SpriteBatch(GraphicsDevice);
        }
        
        public static VertexBuffer CreateVertexBuffer(VertexDeclaration declaration, int vertexcount, BufferUsage usage)
        {
            return new VertexBuffer(GraphicsDevice, declaration, vertexcount, usage);
        }

        public static IndexBuffer CreateIndexBuffer(IndexElementSize elementsize, int indexcount, BufferUsage usage)
        {
            return new IndexBuffer(GraphicsDevice, elementsize, indexcount, usage);
        }

        public static RenderTarget2D CreateRenderTarget2D(int width, int height, SurfaceFormat format, DepthFormat depthformat, int multisamplecount, RenderTargetUsage usage)
        {
            return new RenderTarget2D(GraphicsDevice, width, height, false, format, depthformat, multisamplecount, usage);
        }
    }
}
